class Observer {
    constructor(value) {
        this.walk(value)
    }
    walk(data) {
        for(let key in data) {
            defineActive(data,key,data[key])
        }
    }
}
function defineActive(data,key,value) {
    // 递归劫持
    observe(value)
    Object.defineProperty(data,key,{
        get(){
            console.log('获取值');
            return value
        },
        set(newVal){
            if(newVal == value) return;
            console.log('设置新值');
            value = newVal
        }
    })
}

function observe(value){
    if(Object.prototype.toString.call(value) == '[object Object]' || Array.isArray(value)) {
        return new Observer(value)
    }
}